/**
 * Created by sunshine on 17-5-2.
 */
$(document).ready(function () {
    getlist();
    var data = {index: -1};
    $.ajax({
        url: 'ajaxloginlog',
        dataType: 'json',
        data: data,
        type: 'post',
        success: function (result) {
            var pagination = $('#pagination');
            var pageNum = Math.floor(result.info / 10);
            pagination.prepend('<li><a href="#" data-index="0" id="">&laquo;</a></li>');
            for (var i = 0; i <= pageNum; i++) {
                pagination.append('<li><a href="#" data-index="' + i + '">' + (i + 1) + '</a></li>');
            }
            pagination.append('<li><a href="#" data-index="' + pageNum + '">&raquo;</a></li>');
            $('#pagination li').children().bind("click",getlist);

        }


    })
});

function getlist() {
    try{
        var index = this.getAttribute('data-index');
    }catch(e) {
        //如果不是通过点击分页切换则直接令index为0
        index = 0;
    }
    $.ajax({
        url: 'ajaxloginlog',
        dataType: 'json',
        data: {index: index},
        type: 'post',
        success: function (result) {
            var table = $('#table tbody');
            var html = '';
            for (i in result.info) {
                html = html + '<tr>\
                    <td>登录IP:' + result.info[i].userip + '</td>\
                <td>登入时间:' + result.info[i].userlogintime + '</td>\
                <td>登出时间:' + result.info[i].userlogouttime + '</td>\
                </tr>'
            }
            table.html(html);
        }
    })
}